package org.juc.stream;

import java.util.function.Predicate;

public class PredicateDemo {
    public static void main(String[] args) {
        // 匿名接口实现方式
        anonymousInterface();
        // 使用JDK内置的Predicate实现
        PredicateInterface();

    }

    /**
     * 谓词接口实现
     */
    private static void PredicateInterface() {
        Predicate<String> stringPredicate = new Predicate<String>() {
            @Override
            public boolean test(String o) {
                return o.isEmpty();
            }
        };
        System.out.println(stringPredicate.test("ABC"));
    }

    /**
     * 匿名的接口
     */
    private static void anonymousInterface() {
        TestPredicate testPredicate = new TestPredicate(){
            @Override
            public boolean test(String str) {
                return str.isEmpty();
            }
        };
        System.out.println(testPredicate.test("edf"));
    }

}

/**
 * 测试断言
 *
 * @author Admin
 * @date 2021/11/30
 */
interface TestPredicate{
    boolean test(String str);
}
